package de.au.fi.calc;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import de.au.fi.domain.Stock;


public class CalcHelper {
	
	public static int calculateKgv(Double kgv) {
		if(kgv == null)return 0;
		if(kgv < 12)return 1;
		if(kgv > 16)return -1;
		return 0;
	}
	
	public static Double roundToTwoDigits(Double value) {
		if(value==null)return null;
	    NumberFormat numberFormat = new DecimalFormat("0.00");
	    numberFormat.setRoundingMode(RoundingMode.HALF_UP);
	    return new Double(numberFormat.format(value).replace(",", "."));
	  }
	
	public static List<String> getWknsFromString(String wkns)
	{
		List<String> wknList = new ArrayList<String>();
		StringTokenizer tokenizer = new StringTokenizer(wkns, " ");
		while(tokenizer.hasMoreElements())
		{
			wknList.add((String)tokenizer.nextElement());
		}
		return wknList;
	}
	

	public static Double getDoubleSafe(String value) {
		try {
			return new Double(value);
		} catch (NumberFormatException e) {
			return null;
		}
	}

}
